package com.hlj.ncp.product.controller;

import com.hlj.ncp.common.core.domain.AjaxResult;
import com.hlj.ncp.product.entity.AgriProduct;
import com.hlj.ncp.product.service.IAgriProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 农产品信息 控制层
 */
@Controller
@RequestMapping("/agriProduct")
public class AgriProductController {
    
    @Autowired
    private IAgriProductService agriProductService;
    
    /**
     * 农产品信息管理页面
     */
    @GetMapping("/index")
    public String index() {
        return "agriProduct/index";
    }
    
    /**
     * 获取农产品信息列表
     */
    @PreAuthorize("hasAuthority('agriProduct:list')")
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list(AgriProduct agriProduct) {
        return AjaxResult.success(agriProductService.selectAgriProductList(agriProduct));
    }
    
    /**
     * 获取农产品信息详细信息
     */
    @PreAuthorize("hasAuthority('agriProduct:query')")
    @GetMapping(value = "/{agriProductId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("agriProductId") Long agriProductId) {
        return AjaxResult.success(agriProductService.selectAgriProductById(agriProductId));
    }
    
    /**
     * 新增农产品信息
     */
    @PreAuthorize("hasAuthority('agriProduct:add')")
    @PostMapping
    @ResponseBody
    public AjaxResult add(@RequestBody AgriProduct agriProduct) {
        return AjaxResult.success(agriProductService.insertAgriProduct(agriProduct));
    }
    
    /**
     * 修改农产品信息
     */
    @PreAuthorize("hasAuthority('agriProduct:edit')")
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody AgriProduct agriProduct) {
        return AjaxResult.success(agriProductService.updateAgriProduct(agriProduct));
    }
    
    /**
     * 删除农产品信息
     */
    @PreAuthorize("hasAuthority('agriProduct:remove')")
    @DeleteMapping("/{agriProductIds}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] agriProductIds) {
        return AjaxResult.success(agriProductService.deleteAgriProductByIds(agriProductIds));
    }
    
    /**
     * 获取农产品类别选项
     */
    @GetMapping("/categories")
    @ResponseBody
    public AjaxResult getCategories() {
        // 返回农产品类别选项
        return AjaxResult.success(new Object[][]{
            {"1", "粮食"},
            {"2", "蔬菜"},
            {"3", "水果"},
            {"4", "肉禽蛋"},
            {"5", "水产"},
            {"6", "其他"}
        });
    }
} 